using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using yq.IBase;
using yq.Dictionary;
using yq.Basis;
using yq.Model.Logic;
using System.Collections;
using Db;
using System.Data.Common;

namespace yq.Model.Base
{
    ///<summary>
    /// Sys_Task - 定时任务 - 对象基础类
    /// </summary>
    ///<typeparam name="T"></typeparam>
    public abstract class ISysTask<T> : ModelBase<SysTask> where T : SysTask, new()
    {
        /// <summary>
        /// 写入主键值
        /// </summary>
        /// <param name="Id">主键</param>
        protected internal override void SetKeyValue(dynamic Id)
        {
            this.Rowid = Id;
        }

        /// <summary>
        /// 获取主键值
        /// </summary>
        /// <returns></returns>
        protected internal override dynamic GetKeyValue()
        {
            return Rowid;
        }

        /// <summary>
        /// 为本对象赋值
        /// </summary>
        /// <param name="dy"></param>
        public override void SetValue(dynamic dy)
        {
            this.Rowid = dy.Rowid;
            this.Title = dy.Title;
            this.RunPath = dy.RunPath;
            this.State = dy.State;
            this.Types = dy.Types;
            this.Interval = dy.Interval;
            this.StartTime = dy.StartTime;
            this.CreateTtime = dy.CreateTtime;
            this.NextTime = dy.NextTime;
            this.OutInterval = dy.OutInterval;
            this.OutTime = dy.OutTime;
            this.Detailed = dy.Detailed;
            this.Json = dy.Json;
            this.Version = dy.Version;
        }

        #region 定义属性


        /// <summary>
        /// 自增
        /// </summary>
        private String _Rowid = "";

        /// <summary>
        /// 自增
        /// </summary>
        public String Rowid
        {
            get
            {
                return (this._Rowid);
            }

            set
            {
                _Rowid = value;
            }
        }


        /// <summary>
        /// 任务名称
        /// </summary>
        private String _Title = "";

        /// <summary>
        /// 任务名称
        /// </summary>
        public String Title
        {
            get
            {
                return (this._Title);
            }

            set
            {
                _Title = value;
            }
        }


        /// <summary>
        /// 执行路径
        /// </summary>
        private String _RunPath = "";

        /// <summary>
        /// 执行路径
        /// </summary>
        public String RunPath
        {
            get
            {
                return (this._RunPath);
            }

            set
            {
                _RunPath = value;
            }
        }


        /// <summary>
        /// 状态
        /// </summary>
        private int _State = -1;

        /// <summary>
        /// 状态
        /// </summary>
        public yq.Enums.SysTask.State State
        {
            get
            {
                return (yq.Enums.SysTask.State)this._State;
            }

            set
            {
                _State = value.GetHashCode();
            }
        }


        /// <summary>
        /// 类型
        /// </summary>
        private int _Types = -1;

        /// <summary>
        /// 类型
        /// </summary>
        public yq.Enums.SysTask.Types Types
        {
            get
            {
                return (yq.Enums.SysTask.Types)this._Types;
            }

            set
            {
                _Types = value.GetHashCode();
            }
        }


        /// <summary>
        /// 间隔值
        /// </summary>
        private String _Interval = "";

        /// <summary>
        /// 间隔值
        /// </summary>
        public String Interval
        {
            get
            {
                return (this._Interval);
            }

            set
            {
                _Interval = value;
            }
        }


        /// <summary>
        /// 开始运行时间
        /// </summary>
        private DateTime _StartTime = DateTime.MinValue;

        /// <summary>
        /// 开始运行时间
        /// </summary>
        public DateTime StartTime
        {
            get
            {
                return (this._StartTime);
            }

            set
            {
                _StartTime = value;
            }
        }


        /// <summary>
        /// 创建时间
        /// </summary>
        private DateTime _CreateTtime = DateTime.MinValue;

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTtime
        {
            get
            {
                return (this._CreateTtime);
            }

            set
            {
                _CreateTtime = value;
            }
        }


        /// <summary>
        /// 下次运行时间
        /// </summary>
        private DateTime _NextTime = DateTime.MinValue;

        /// <summary>
        /// 下次运行时间
        /// </summary>
        public DateTime NextTime
        {
            get
            {
                return (this._NextTime);
            }

            set
            {
                _NextTime = value;
            }
        }


        /// <summary>
        /// 运行超时秒数
        /// </summary>
        private int _OutInterval = 3600;

        /// <summary>
        /// 运行超时秒数
        /// </summary>
        public int OutInterval
        {
            get
            {
                return (this._OutInterval);
            }

            set
            {
                _OutInterval = value;
            }
        }


        /// <summary>
        /// 运行超时时间
        /// </summary>
        private DateTime _OutTime = DateTime.MinValue;

        /// <summary>
        /// 运行超时时间
        /// </summary>
        public DateTime OutTime
        {
            get
            {
                return (this._OutTime);
            }

            set
            {
                _OutTime = value;
            }
        }


        /// <summary>
        /// 任务说明
        /// </summary>
        private String _Detailed = "";

        /// <summary>
        /// 任务说明
        /// </summary>
        public String Detailed
        {
            get
            {
                return (this._Detailed);
            }

            set
            {
                _Detailed = value;
            }
        }


        /// <summary>
        /// json参数
        /// </summary>
        private String _Json = "";

        /// <summary>
        /// json参数
        /// </summary>
        public String Json
        {
            get
            {
                return (this._Json);
            }

            set
            {
                _Json = value;
            }
        }


        #endregion 定义属性

        protected internal override void SetValue(SysTask info, DataRow row)
        {
            if (row == null)
            {
                info.IsLoad = false;
            }
            else
            {
                info.IsLoad = true;

                if (row["Rowid"] != DBNull.Value)
                {
                    info.Rowid = row["Rowid"].ToString();
                }


                if (row["Title"] != DBNull.Value)
                {
                    info.Title = row["Title"].ToString();
                }


                if (row["RunPath"] != DBNull.Value)
                {
                    info.RunPath = row["RunPath"].ToString();
                }


                if (row["State"] != DBNull.Value)
                {
                    info.State = (yq.Enums.SysTask.State)(row["State"]);
                }


                if (row["Types"] != DBNull.Value)
                {
                    info.Types = (yq.Enums.SysTask.Types)(row["Types"]);
                }


                if (row["Interval"] != DBNull.Value)
                {
                    info.Interval = row["Interval"].ToString();
                }


                if (row["StartTime"] != DBNull.Value)
                {
                    info.StartTime = Convert.ToDateTime(row["StartTime"]);
                }


                if (row["CreateTtime"] != DBNull.Value)
                {
                    info.CreateTtime = Convert.ToDateTime(row["CreateTtime"]);
                }


                if (row["NextTime"] != DBNull.Value)
                {
                    info.NextTime = Convert.ToDateTime(row["NextTime"]);
                }


                if (row["OutInterval"] != DBNull.Value)
                {
                    info.OutInterval = Convert.ToInt32(row["OutInterval"]);
                }


                if (row["OutTime"] != DBNull.Value)
                {
                    info.OutTime = Convert.ToDateTime(row["OutTime"]);
                }


                if (row["Detailed"] != DBNull.Value)
                {
                    info.Detailed = row["Detailed"].ToString();
                }


                if (row["Json"] != DBNull.Value)
                {
                    info.Json = row["Json"].ToString();
                }


                if (row["Version"] != DBNull.Value)
                {
                    info.Version = row["Version"].ToString();
                }

            }

        }

        protected internal override void GetDbParameters(DbCommand comm, SysTask info, DbHelper cn)
        {

            cn.AddInParameter(comm, "@Rowid", DbType.String, ParameterTool.GetObj(info._Rowid));


            cn.AddInParameter(comm, "@Title", DbType.String, ParameterTool.GetObj(info._Title));


            cn.AddInParameter(comm, "@RunPath", DbType.String, ParameterTool.GetObj(info._RunPath));


            cn.AddInParameter(comm, "@State", DbType.Int32, ParameterTool.GetObj(info._State));


            cn.AddInParameter(comm, "@Types", DbType.Int32, ParameterTool.GetObj(info._Types));


            cn.AddInParameter(comm, "@Interval", DbType.String, ParameterTool.GetObj(info._Interval));


            cn.AddInParameter(comm, "@StartTime", DbType.DateTime, ParameterTool.GetObj(info._StartTime));


            cn.AddInParameter(comm, "@CreateTtime", DbType.DateTime, ParameterTool.GetObj(info._CreateTtime));


            cn.AddInParameter(comm, "@NextTime", DbType.DateTime, ParameterTool.GetObj(info._NextTime));


            cn.AddInParameter(comm, "@OutInterval", DbType.Int32, ParameterTool.GetObj(info._OutInterval));


            cn.AddInParameter(comm, "@OutTime", DbType.DateTime, ParameterTool.GetObj(info._OutTime));


            cn.AddInParameter(comm, "@Detailed", DbType.String, ParameterTool.GetObj(info._Detailed));


            cn.AddInParameter(comm, "@Json", DbType.String, ParameterTool.GetObj(info._Json));


            cn.AddInParameter(comm, "@Version", DbType.String, Guid.NewGuid().ToString());


            cn.AddInParameter(comm, "@_versionOdl", DbType.String, info._Version);

        }

    }
}